package vn.edu.saigontech.ncms.web.study;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.Map;

import vn.edu.saigontech.ncms.model.info.AbstractReceipt;
import vn.edu.saigontech.ncms.model.info.Student;
import vn.edu.saigontech.ncms.service.StudentService;
import vn.edu.saigontech.ncms.util.DateUtil;
import vn.edu.saigontech.ncms.web.BaseAction;

@SuppressWarnings("serial")
public class StudyAction extends BaseAction {
	
	private String fromDate;
	private String toDate;
	
	private Date fromDateDate;
	private Date toDateDate;
	
	public String reportStudentList() {
		this.fromDateDate = DateUtil.fromString(this.fromDate, this.i18n("format.date"));
		this.toDateDate = DateUtil.fromString(this.toDate, this.i18n("format.date"));
		Map<Student, List<AbstractReceipt>> map = StudentService.INSTANCE.findStudy(this.fromDateDate, this.toDateDate, false);
		Map<Student, List<AbstractReceipt>> unstudyMap = StudentService.INSTANCE.findUnStudy(this.fromDateDate, this.toDateDate);
		List<Student> students = new ArrayList<Student>(map.keySet());
		
		Collections.sort(students, new Comparator<Student>() {
			@Override
			public int compare(Student o1, Student o2) {
				return o1.getFirstName().compareTo(o2.getFirstName());
			}
		});
		REQUEST().setAttribute("map", map);
		REQUEST().setAttribute("students", students);
		REQUEST().setAttribute("unstudyMap", unstudyMap);
		REQUEST().setAttribute("unstudyStudents", new ArrayList<Student>(unstudyMap.keySet()));
		
		this.addLoggingDetail(BaseAction.REPORT, "logging.student.report");
		return SUCCESS;
	}

	public String getFromDate() {
		return fromDate;
	}

	public void setFromDate(String fromDate) {
		this.fromDate = fromDate;
	}

	public String getToDate() {
		return toDate;
	}

	public void setToDate(String toDate) {
		this.toDate = toDate;
	}
}
